#include "StdAfx.h"
#include "FileIO.h"
#include <fstream>


//-------------------------------------------------------------------------------------------------
bool FileSave(const char *filename, const void *data, size_t count, bool append)
{
//----
//	save data to disk
	std::ios::open_mode openMode = std::ios::out | std::ios::binary;
	if(append)
		openMode |= std::ios::app;

	std::ofstream file(filename, openMode);

	if(!file.good())
	{
		file.close();
		return false;
	}

	file.write((const char *) data, count);
	file.close();

	return true;
}

//-------------------------------------------------------------------------------------------------
bool FileLoad(const char *filename, void *data, size_t count)
{
//----
//	load data from disk
	std::ifstream file(filename, std::ios::in | std::ios::binary);

	if(!file.good())
	{
		file.close();
		return false;
	}

	file.seekg(0, std::ios::end);
	std::streamoff size = file.tellg();

	file.seekg(std::ios::beg);
	file.read((char *) data, size < count ? size : count);
	file.close();

	return true;
}

